package com.company.sort;

import java.util.Random;

/**
 * @author shenhan
 * @create 2020/2/1 12:39
 * @description
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] arr = new int[80000];
        Random random = new Random();
        for (int i = 0; i < 80000; i++) {
            arr[i] = random.nextInt();
        }
        final long l1 = System.currentTimeMillis();
        selectSort(arr);
        final long l2 = System.currentTimeMillis();
        System.out.println(l2 - l1);
    }

    public static void selectSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            int minIndex = i;
            int min = arr[i];
            for (int j = i + 1; j < arr.length; j++) {
                if (min > arr[j]) {
                    min = arr[j];
                    minIndex = j;
                }
            }
            if (minIndex != i) {
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
//            System.out.println("第" + (i + 1) + "轮后~");
//            System.out.println(Arrays.toString(arr));
        }
    }
}
